<template>
	<div>
		<div class="header_bg">

		</div>
		<div class="header header_bg">
			<div class="header_left ellipsis01" style="color:#fff">
				<span class="baiColor">{{content.new_title}}</span>
			</div>
		</div>
		<div class="center" style="margin-top: 47px;">

			<div class="content">
				<div class="index-Details" v-html="content.new_content"></div>
			</div>
			
			<div class="zan">
				<div class="header_right">
					<i onclick="javascript:history.back(-1)" class="iconfont color" style="color: #666;">&#xe612;</i>
					
					<span @click="zan(content)" :class="{'active':content.check}">
						<i class="iconfont">&#xe607;</i>
						{{content.new_num}}
					</span>
					<span>
						<router-link :to="{name:'pinglun',params:{id:content.new_id}}">
							<i class="iconfont">&#xe644;</i>
							{{content.evaluate_num}}
						</router-link>
					</span>
				</div>
			</div>
		</div>
	</div>

</template>

<script>
	export default {
		data() {
			return {
				//获取的文章详情内容
				content: {},
			}
		},
		mounted: function() {
			var _this = this
			//获取这片文章的id  
			var str=window.location.href;
			var num=str.lastIndexOf("/")+1;
			var new_id = str.substring(num)
			var info = window.localStorage.data;
			var params = new URLSearchParams();
			params.append('id', new_id);
			params.append('token', info);
			this.$axios({
				url: "Home/New/new_xq",
				method: "POST",
				data: params
			}).then((res) => {
				if(res.data.code == '1') {
					this.content = res.data.data;
					if(this.content.iszan > 0) {
						if(typeof this.content.check == "undefined") {
							_this.$set(this.content, 'check', true)
						}
					}
				}
			}).catch((err) => {
				console.log(err)
			})
		},
		methods: {

			//详情点赞/取消赞
			zan: function(content) {
				var _this = this;
				var info = window.localStorage.data;
				var params = new URLSearchParams();
				if(typeof _this.content.check == "undefined" || !_this.content.check ) {
					//点赞
					let id = _this.content.new_id;
					_this.content.new_num ++;
					params.append('type', 1);
					params.append('id', id);
					params.append('token', info);	//客户秘钥（信息）
					this.$axios({
						url: "Home/New/new_zan",
						method: "POST",
						data: params
					}).then((res) => {
						_this.$set(content, 'check', true);
					}).catch(function(err) {
						console.log(err)
					});
					//点赞结束	
				} else if(_this.content.check == true) {
					//取消赞
					let id = _this.content.new_id;
					_this.content.new_num --;
					params.append('type', 1);
					params.append('id', id);
					params.append('token', info);	//客户秘钥（信息）
					this.$axios({
						url: "Home/New/del_zan",
						method: "POST",
						data: params
					}).then((res) => {
						_this.content.check = false
						//需要变色
					}).catch(function(err) {
						console.log(err)
					});
				}
			},
		}
	}
</script>
<style type="text/css">
	.index-Details p{
		color: #666 !important;
		font-size: 16px !important;
		line-height: 20px !important;
	}
	.index-Details p img{
		width: 100% !important;
		height: 130px !important;
	}
</style>

<style scoped="scoped">
	@import "../css/public.css";
	@import url("../css/iXiangQing.css");
	.baiColor {
		font-size: 15px;
		color: #F0F0F0;
	}
</style>